package edu.sctu.zhuyingzhi.month201506.day20150618.timerV4;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by user13 on 2015/6/18.
 */
public class AwtControl implements Runnable{

    public static JLabel time  = new JLabel(0+":"+0);   //设置时间


    @Override
    public void run() {

        TimerThread timerThread = new TimerThread();
        Frame frame = new Frame("计时器");

        frame.setSize(300,300);
        frame.setLocation(200,100);
        frame.setLayout(new FlowLayout(FlowLayout.CENTER,0,150));

        Button startbutton = new Button("start");
        Button pausebutton = new Button("pause");
        Button stopbutton = new Button("stop");
        Button readbutton = new Button("read");


        frame.add(startbutton);
        frame.add(pausebutton);
        frame.add(time);                              //添加时间
        frame.add(stopbutton);
        frame.add(readbutton);

        frame.setVisible(true);


        startbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                timerThread.startTimer();
            }
        });
        pausebutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                timerThread.pause();
            }
        });
        stopbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                timerThread.stop();
            }
        });
        readbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                timerThread.read();
            }
        });
    }
}
